﻿
@{

}

@section Header{
    <link rel="stylesheet" href="@Url.Action("GetModuleCSS", "System", new { moduleName = BookLibrary.ModuleDefiniation.MODULE_NAME, fileName = "Content/module.css" })" />
}


<h1>Available Books</h1>

<div>
    <table class="table">
        <thead>
            <tr>
                <th>BookId</th>
                <th>Book Name</th>
                <th>ISBN</th>
                <th>Date Issued</th>
                <th>Action</th>
            </tr>
        </thead>
        <tbody>
            @if (Model != null && Model.Count > 0)
            {
                foreach (var item in Model)
                {
                    <tr>
                        <td>@item.BookId</td>
                        <td>@item.BookName</td>
                        <td>@item.ISBN</td>
                        <td>@item.DateIssued.ToString("yyyy-MM-dd")</td>
                        <td><span class="btn btn-primary" onclick="rentBook('@item.BookId')">Rent</span></td>
                    </tr>
                }
            }
            else
            {
                <tr>
                    <td colspan="5">No Records.</td>
                </tr>
            }
        </tbody>
    </table>
</div>

@section Scripts{
    <script type="text/javascript">
        function rentBook(id) {
            $.ajax({
                url: '@Url.Action("RentBook","Book")?bookId=' + id,
                method: 'PUT',
                success: function (data) {
                    window.location.reload();
                }
            });
        }
    </script>

}
